// pages/my_zong/my_zong.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checked: false,
    array: ['微信', '线下'],
    index: "",
    ifxian: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var did = wx.getStorageSync('did');
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      did: did,
    })
    that.getDetail();
  },
  getDetail:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/green.guidance_detail",
      data:{
        openid:wx.getStorageSync('openid'),
      },
      success:function(res){
        that.setData({
          list:res.data
        })
      }
    })
  },
  
  //明细
  mingClick: function () {
    var openid = wx.getStorageSync('openid')
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/usermx/usermx?openid=' + openid,
    })
  },
  //须知
  xuzhi: function () {
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/xuzhi/xuzhi',
    })
  },
  //设置最大提现金额
  money: function (e) {
    var that = this
    var money = that.data.money
    //console.log(e)
    if (e.detail.value >= money) {
      var value = money
      that.setData({
        value: value
      })
    }
  },
  //提交
  subClick: function (e) {
    var that = this;
    var base = that.data.base
    var zdtx = parseInt(base.min_money)
    var txsx = base.expert_fee
    var zid = that.data.zid
    var formobj = e.detail.value;
    console.log(e)
    formobj.openid = wx.getStorageSync('openid');
    var tx_cost = parseFloat(formobj.tx_cost)
    var sj_cost = parseFloat(formobj.sj_cost)
    var zztx = tx_cost - sj_cost * txsx
    var sxf = sj_cost * txsx
    let countmoney = that.data.countmoney
    var ifxian = that.data.ifxian
    if (e.detail.value.sj_cost.length == 0) {
      wx.showModal({
        content: '您的账户暂无金额',
      })
    } else if (e.detail.value.tx_cost.length == 0) {
      wx.showModal({
        content: '请输提现金额',
      })
    } else if (e.detail.value.tx_type == '' || e.detail.value.tx_type == null) {
      wx.showModal({
        content: '请选择提现方式',
      })
    } else if (tx_cost > sj_cost) {
      wx.showModal({
        content: '超出实际金额',
      })
    } else if (tx_cost < zdtx) {
      wx.showModal({
        content: '提现金额必须大于等于' + zdtx,
      })
    } else {
      wx.showModal({
        content: ' 实际到帐' + zztx + '扣除' + sxf + '手续费',
        success: function (res) {
          if (res.confirm) {
            console.log(res.confirm)
            console.log('用户点击确定');
            var tx_cost = e.detail.value.tx_cost;
            var tx_type = e.detail.value.tx_type;
            var tx_admin = e.detail.value.tx_admin
            var openid = wx.getStorageSync('openid');
            app.util.request({
              url: 'entry/wxapp/zhuanjia.saveTx',
              data: {
                sj_cost: zztx,
                tx_cost: tx_cost,
                tx_type: tx_type,
                openid: openid,
                tx_admin: tx_admin,
                zjid: zid
              },
              success: function (res) {
                console.log(res)
                if (res.data.code == 1) {
                  wx.showToast({
                    title: '提交失败',
                  })
                } else {
                  wx.showToast({
                    title: '提交成功',
                  })
                  wx.redirectTo({
                    url: '../my/my'
                  })
                }

              },

              fail: function (err) {
                console.log(err);
              }
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      });
      //获取用户信息
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getBase()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getBase: function () {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/index.tixiansite',
      success: function (res) {
        console.log(res)
        that.setData({
          base: res.data
        })
      },
      fail: function (err) {
        //console.log(err)
      },
    })
  },
})